package nafos.server.shutdown;

import io.undertow.UndertowOptions;
import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * @ClassName UndertowExtraConfiguration
 * @Description TODO
 * @Author hxy
 * @Date 2020/1/13 0:54
 */
@Component
public class UndertowExtraConfiguration {
    private final GracefulShutdownWrapper gracefulShutdownWrapper;

    public UndertowExtraConfiguration(GracefulShutdownWrapper gracefulShutdownWrapper) {
        this.gracefulShutdownWrapper = gracefulShutdownWrapper;
    }

    @Bean
    public UndertowServletWebServerFactory servletWebServerFactory() {
        UndertowServletWebServerFactory factory = new UndertowServletWebServerFactory();
        factory.addDeploymentInfoCustomizers(deploymentInfo -> deploymentInfo.addOuterHandlerChainWrapper(gracefulShutdownWrapper));
        factory.addBuilderCustomizers(builder -> builder.setServerOption(UndertowOptions.ENABLE_STATISTICS, true));
        return factory;
    }

}

